Skip to content

Conversation

@krystophny
Copy link
Collaborator

Summary

  • Implement proper Huffman compression to fix 100x PNG file bloat
  • Replace uncompressed DEFLATE blocks with efficient compression algorithm
  • Restore normal PNG file sizes from 1.4MB to expected ~24KB range

Technical Verification Evidence

BEFORE FIX:

  • Simple plot: 1,440,774 bytes (1.4MB)
  • Complex plot: 5,761,704 bytes (5.7MB)

AFTER FIX:

  • Simple plot: 23,936 bytes (~24KB) - 60x smaller!
  • Complex plot: 927,928 bytes (~928KB) - 6x smaller!

Local Test Results:

PNG File Size Scaling Test Results:
======================================
Empty plot size:         7265
Simple plot size:       23936
Complex plot size:     927928
PASS: PNG file sizes scale appropriately with content

Full Test Suite: All 107 tests pass with no regressions
Build Status: Clean compilation with zero errors
Performance Impact: Dramatic file size reduction with proper compression

Implementation Details

  • Modified zlib_compress() in fortplot_zlib_core.f90
  • Changed from compress_with_uncompressed_blocks() to compress_with_fixed_huffman()
  • Utilizes existing, well-tested Huffman compression implementation
  • Maintains full ZLIB format compliance with proper headers and checksums

Fixes #963

- Replace uncompressed DEFLATE blocks with Huffman compression
- Fix 100x file size bloat from 1.4MB to 24KB for simple plots
- Use existing compress_with_fixed_huffman instead of uncompressed blocks
- All tests pass with dramatic file size reduction
- Resolves P0 ZLIB compression system recovery issue
@krystophny krystophny merged commit 2b65a2d into main Aug 31, 2025
3 checks passed
@krystophny krystophny deleted the fix-zlib-compression-963 branch August 31, 2025 15:18
krystophny added a commit that referenced this pull request Aug 31, 2025
CRITICAL PNG Issue Fixed: File sizes reduced from 1.44MB to 47KB (30x smaller)

## Problem
PNG files were 1.44MB due to broken ZLIB compression that was using
inefficient uncompressed DEFLATE blocks instead of proper Huffman coding.
This caused:
- Massive PNG file bloat (60x normal size)
- FFmpeg animation failures due to invalid compression
- User workflow disruption

## Root Cause
Recent commits reverted the working compression from PR #964 (commit 2b65a2d)
which had switched from uncompressed blocks to fixed Huffman compression.

## Solution
Restore the working implementation by switching back to:
- compress_with_fixed_huffman() instead of compress_with_uncompressed_blocks_efficient()
- This was the proven solution from commit 2b65a2d that achieved 60x file size reduction

## Evidence
BEFORE: basic_user_plot.png = 1,440,665 bytes (1.44MB)
AFTER:  basic_user_plot.png = 47,751 bytes (47KB) ✓

## Verification
- All 107 tests pass ✓
- PNG generation working ✓
- File sizes dramatically reduced ✓
- No regressions introduced ✓

Fixes #983

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CRITICAL: ZLIB compression system-wide failure causes massive PNG bloat and corruption

2 participants